package com.ruoyi.web.controller.dangerControl;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.dangerControl.domain.HdCheckPlan;
import com.ruoyi.dangerControl.dto.LocationDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dangerControl.domain.Location;
import com.ruoyi.dangerControl.service.ILocationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 地理位置Controller
 *
 * @author lth
 * @date 2023-12-14
 */
@RestController
@RequestMapping("/dangerControl/location")
public class LocationController extends BaseController
{
    @Autowired
    private ILocationService locationService;

    /**
     * 查询地理位置列表
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:location:list')")
    @GetMapping("/list")
    public TableDataInfo list(Location location)
    {
        startPage();
        List<Location> list = locationService.selectLocationList(location);
        return getDataTable(list);
    }

    /**
     * 导出地理位置列表
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:location:export')")
    @Log(title = "地理位置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Location location)
    {
        List<Location> list = locationService.selectLocationList(location);
        ExcelUtil<Location> util = new ExcelUtil<Location>(Location.class);
        util.exportExcel(response, list, "地理位置数据");
    }

    /**
     * 获取地理位置详细信息
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:location:query')")
    @GetMapping(value = "/{locationId}")
    public AjaxResult getInfo(@PathVariable("locationId") String locationId)
    {
        return success(locationService.selectLocationByLocationId(locationId));
    }

    /**
     * 新增地理位置
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:location:add')")
    @Log(title = "地理位置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Location location)
    {
        return toAjax(locationService.insertLocation(location));
    }

    /**
     * 修改地理位置
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:location:edit')")
    @Log(title = "地理位置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Location location)
    {
        return toAjax(locationService.updateLocation(location));
    }

    /**
     * 删除地理位置
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:location:remove')")
    @Log(title = "地理位置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{locationIds}")
    public AjaxResult remove(@PathVariable String[] locationIds)
    {
        return toAjax(locationService.deleteLocationByLocationIds(locationIds));
    }



    /**
     * 查询位置列表
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:plan:list')")
    @GetMapping("/getLocationList")
    public AjaxResult getLocationList()
    {
        LocationDto locationDto = locationService.getLocationList();
        return success(locationDto);
    }

}
